

require(['./config'], () =>{
    require(['request','template','header','footer'],(request,template)=>{
            class Cate {
                constructor (){
                    this.init ()
                 

                }
                init (){
                   
                    const id = window.location.hash.slice(1)
                    // console.log(id)
                    request.getCategory(id).then( resp  =>{
                        // console.log(resp)
                    if (resp.code === 200 ) {
                        const { name } = resp.data.category
                        // console.log({name})
                        // const { list } = resp.data.items
                        
                        const arr = resp.data.items.list
                            let curNum =  9 ,
                            len  = Math.ceil( arr.length / curNum) 
                            //    console.log(len)                   
                            for (let i = 0 ;i<len;i++){
                               //遇到的问题 默认为第一页，这样去slice,等点击的时候在去slice 
                            let  content = arr.slice(0,curNum) 
                            $('#commodityList').html(template ('commodityTemplate',{content}))
                            console.log(content)
                            $(`<li>${i+1}</li>`).appendTo('.paging').on('click',function(){
                                content = arr.slice((i)*curNum,(i+1)*curNum) 
                                $(this).addClass("active") 
                                $(this).prevAll().removeClass("active")
                                $(this).nextAll().removeClass("active")
                                $('#commodityList').html(template ('commodityTemplate',{content}))
                            })
                            // content = arr.slice(0,curNum)
                            $('.paging').find("li:first").addClass("active")
                           
                        }
                           
                            
                        // $('#titleList').text(template ('titleTemplate',{ name }));
                        $('#categoryList').html(template ('cateTemplate',{ name }));
                        
                        
                    }


                    })

                }
            }






            new Cate ()

    })
})